#include "BoxModel.h"
#include "ListPanel.h"

BoxModel::BoxModel(ListPanel* panel, deque<Eatable>& food) :
	items(food) {
	this->panel = panel;
}

int BoxModel::getNumRows() {
	return items.size();
}

/*
 * TODO: cleanup magic numbers
 */
void BoxModel::paintListBoxItem(int rowNumber, Graphics& g, int width, int height, bool rowIsSelected) {

	if (rowIsSelected) {
		g.setColour(Colour(200, 210, 220));
	} else {
		g.setColour(rowNumber % 2 ? Colours::white : Colour(240, 240, 255));
	}
	g.fillRect(10, 1, width - 10, height - 3);
	g.setColour(Colours::black);
	g.setFont(Font(Font::getDefaultSansSerifFontName(), 16, Font::plain));
	g.drawMultiLineText(items[rowNumber].getName().substring(0, 150), 90, 15, width - 100);
//	g.drawFittedText(items[rowNumber].getName(), 90, 5, width - 5, height - 5, Justification::topLeft, 1);

//	NutritionalInfo& info = items[rowNumber].getNutritionalInfo();
//	String text = String::formatted(T("%3.f cal"), info.calories);

	g.setColour(Colours::grey);
//	g.drawSingleLineText(text, 90, 37);
	//	g.drawSingleLineText(time, 90, 60);

	const Image* image = items[rowNumber].getImage();
	if (image) {
		g.drawImage(image, 14, 3, 65, 65, 0, 0, image->getWidth(), image->getHeight(), false);
	}
	g.setColour(rowIsSelected ? Colours::grey : Colours::lightgrey);
	g.drawVerticalLine(82, 0, height - 1);
	g.drawVerticalLine(10, 0, height - 1);
	g.drawHorizontalLine(height - 2, 10, width);
	g.drawHorizontalLine(0, 10, width);
}

void BoxModel::listBoxItemClicked(int row, const MouseEvent& e) {
	panel->showItemView(row);
}

void BoxModel::mouseDoubleClick(const MouseEvent& e) {
	std::cout << "double click" << std::endl;
}
